<?php
namespace Admin\Controller;
use Think\Controller;
class CommonController extends Controller {
	public function _initialize(){
		if(!isset($_SESSION['adid']) || !isset($_SESSION['username'])){
			$this->redirect('/Admin/login');
		}
	}
	/*无限极分类*/
	public function limitless($data,$pid=0,$level=0){
		$arr=array();
		foreach($data as $v){
			if($v['pid']==$pid){
				$v['level']=$level;
				$v['html']=str_repeat('-', $level*5);
				$arr[]=$v;
				$arr=array_merge($arr,$this->limitless($data,$v['cid'],$level+1));
			}
		}
		return $arr;
	}
	/**
	 * @param $path  配置项文件
	 * 
	 * */
	public function edit($path='lvconfig.php'){
		//载入规则配置项  lvconfig.php
    	$path=COMMON_PATH .'/Conf/'.$path;
		$config=array_merge(include $path,$_POST);
		$str="<?php \r\n return  ".var_export($config,true).";\r\n ?>";
		if(file_put_contents($path, $str)){
			$this->success('修改成功！');	
		}else{
			$this->success('修改失败！');
		}
	}
}